package client;

import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import serveur.Information;

public class LanceClient {
	
	public static void main(String[] args) {
	    System.out.println("Lancement du client");
	  
	    try {
	    	String url = "rmi://" + InetAddress.getLocalHost().getHostAddress() + "/RMI";
	      Remote r =  Naming.lookup(url);
	    		  //Naming.lookup("rmi://192.168.0.43/RMI");
	      System.out.println(r);
	      if (r instanceof Information) {
	    	  Calendar calendar1 = new GregorianCalendar();
	  		int heure1 = calendar1.get(java.util.Calendar.HOUR_OF_DAY);
	  		int minute1 = calendar1.get(java.util.Calendar.MINUTE);
	  		int seconde1 = calendar1.get(java.util.Calendar.SECOND);
	    	  int i =10000;
	    	  while(i>0){
	        String s = ((Information) r).getInformation();
	        System.out.println("chaine renvoyee = " + s);
	        i=i-1;
	    	  }
	    	  
	    	  Calendar calendar2 = new GregorianCalendar();
				int heure2 = calendar2.get(java.util.Calendar.HOUR_OF_DAY);
				int minute2 = calendar2.get(java.util.Calendar.MINUTE);
				int seconde2 = calendar2.get(java.util.Calendar.SECOND);
			
				System.out.println("heure : " + heure1 + " minute : "+ minute1+ " seconde : "+ seconde1);
				
				System.out.println("heure : " + heure2 + " minute : "+ minute2+ " seconde : "+ seconde2);
				
	      }
	    } catch (MalformedURLException e) {
	      e.printStackTrace();
	    } catch (RemoteException e) {
	      e.printStackTrace();
	    } catch (NotBoundException e) {
	      e.printStackTrace();
	    } catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    System.out.println("Fin du client");
	  }

}
